package com.lwj.liwanjia.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.lwj.liwanjia.R;
import com.lwj.liwanjia.bean.MySpBean;
import com.lwj.liwanjia.utils.BaseUtils;

import java.util.List;

/**
 * Created by 001 on 2017/9/9.
 */

public class WoDeFaBuAdapter extends RecyclerView.Adapter<WoDeFaBuAdapter.ViewHolder> {

    private Context mContext;
    private List<MySpBean.DataBean> mList;

    public WoDeFaBuAdapter(Context mContext,List<MySpBean.DataBean> mList) {
        this.mContext = mContext;
        this.mList = mList;
    }

    @Override
    public WoDeFaBuAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

        View view = LayoutInflater.from(mContext).inflate(R.layout.adapter_wo_de_fa_bu, parent, false);

        ViewHolder holder = new ViewHolder(view);

        return holder;
    }

    @Override
    public void onBindViewHolder(WoDeFaBuAdapter.ViewHolder holder, int position) {

        MySpBean.DataBean bean = mList.get(position);

        Glide.with(mContext).load(bean.getCommodityimages()).into(holder.iv_photo);
        holder.tv_name.setText(bean.getCommodityName());
        holder.tv_content.setText(bean.getCommodityInfo()+"");
        holder.tv_money.setText("¥"+bean.getCommodityVipPrice());

        long time = bean.getTime();
        String timeResult = BaseUtils.getString(String.valueOf(time/1000));
        holder.tv_time.setText(timeResult);

    }

    @Override
    public int getItemCount() {
        return mList.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder {

        ImageView iv_photo;
        TextView tv_name;
        TextView tv_content;
        TextView tv_money;
        TextView tv_time;

        public ViewHolder(View itemView) {
            super(itemView);

            iv_photo = (ImageView) itemView.findViewById(R.id.iv_photo);
            tv_name = (TextView) itemView.findViewById(R.id.tv_name);
            tv_content = (TextView) itemView.findViewById(R.id.tv_yongHuPinJia);
            tv_money = (TextView) itemView.findViewById(R.id.et_money);
            tv_time = (TextView) itemView.findViewById(R.id.tv_time);
        }
    }
}
